import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:sph_shipper/AppConfig/Config.dart';
import 'package:sph_shipper/Main/Settings/CompanyProfile.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../AppConfig/RouteAct.dart';
import '../../http/NoLoadingGetApi.dart';
import '../../l10n/messages.dart';

class AboutSPH extends StatefulWidget {
  const AboutSPH({super.key});

  @override
  State<AboutSPH> createState() => _AboutSPHState();
}

class _AboutSPHState extends State<AboutSPH> {
  @override
  Widget build(BuildContext context) {
    var messages = AppLocalizations.of(context)!;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: Colors.white,
        leading: IconButton(icon: Icon(Icons.arrow_back_ios,color: Colors.black,),onPressed: (){Navigator.pop(context);},),
        title: Text(messages["关于速配货"],style: TextStyle(fontWeight: FontWeight.w300,fontSize: 16.sp),),
      ),
      body: ListView(

        children: [
          SizedBox(height: 25.h,),
          Image.asset("lib/Images/login/180logo.png",width: 76.w,height: 76.h,),
          SizedBox(height: 10.h,),
          Center(
            child:  Text(messages["速配货货主版"],style: TextStyle(color: Colors.black,fontSize: 13.sp),),
          ),
          SizedBox(height: 5.h,),
          Center(
            child:  Text("V1.0.0",style: TextStyle(color: Colors.black,fontSize: 13.sp),),
          ),
          SizedBox(height: 20.h,),
          GestureDetector(
            child:   Container(
              padding: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h,),
              color: Colors.white,
              // height: 40.h,
              child: Column(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(messages["检查更新"],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                      Row(
                        children: [
                          Icon(Icons.arrow_forward_ios,color: MyColors.authTipColor,size: 14,),
                        ],
                      )
                    ],
                  ),
                  SizedBox(height: 8.h,),
                  Divider(height: 1,color: MyColors.backgreyColor,),
                ],
              ),
            ),
            onTap: () {
              NoLoadinggetApiManager.getData(
                  context,
                  "api/system/dev/dict/list",
                  {'category':'BIZ','parentId':'1808424071131934722'},
                      (responseData)  {
                    setState(() {
                      if(responseData['data'][0]['extJson']!="v1.0.0"){
                        showDialog(
                          barrierDismissible: false,
                          context: context,
                          builder: (BuildContext context) {
                            return Align(
                              alignment: Alignment.center,
                              child: BrnDialog(
                                titleText: "温馨提示",
                                messageText: "速配货有新的版本上线，请前往更新。",
                                actionsWidget: [
                                  TextButton(
                                    onPressed: () {
                                      Navigator.pop(context);
                                    },
                                    child: Text(
                                      "下次再说",
                                      style: TextStyle(color: MyColors.textColor, fontSize: 14.sp),
                                    ),
                                  ),
                                  TextButton(
                                    onPressed: ()async {
                                      Navigator.pop(context);
                                      const url = 'https://www.sph56.cn';
                                      if (await canLaunch(url)) {
                                        await launch(url);
                                      } else {
                                        throw 'Could not launch $url';
                                      }
                                    },
                                    child: Text(
                                      "现在就去",
                                      style: TextStyle(color: MyColors.themeColor, fontSize: 14.sp),
                                    ),
                                  ),
                                ],
                              ),
                            );
                          },
                        );
                      }
                      else{
                        showDialog(
                          barrierDismissible: false,
                          context: context,
                          builder: (BuildContext context) {
                            return Align(
                              alignment: Alignment.center,
                              child: BrnDialog(
                                titleText: "温馨提示",
                                messageText: "当前已是最新版本。",
                                actionsWidget: [
                                  TextButton(
                                    onPressed: () {
                                      Navigator.pop(context);
                                    },
                                    child: Text(
                                      "确认",
                                      style: TextStyle(color: MyColors.textColor, fontSize: 14.sp),
                                    ),
                                  ),
                                ],
                              ),
                            );
                          },
                        );
                      }
                    });

                  },
                );

            },
          ),
          GestureDetector(
            child:   Container(
              padding: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h,),
              color: Colors.white,
              // height: 40.h,
              child: Column(
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(messages["公司简介"],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                      Row(
                        children: [
                          Icon(Icons.arrow_forward_ios,color: MyColors.authTipColor,size: 14,),
                        ],
                      )
                    ],
                  ),
                  SizedBox(height: 8.h,),
                  Divider(height: 1,color: MyColors.backgreyColor,),
                ],
              ),
            ),
            onTap: () {
              Navigator.push( context, FadeRoute(page:CompanyProfile()));
            },
          ),
        ],
      ),
    );
  }
}
